﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 文件名：ClsBillManageDAL.cs
/// 作  者：li/SAM
/// 时  间：2006.11.18/2007-01-10
/// 说  明：ClsBillManageDAL类信息相关处理
/// </summary>
public class ClsBillManageDAL
{
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    /// <summary>
    /// 获取票据管理信息
    /// </summary>
    /// <returns>返回票据管理信息数据集</returns>
    public DataSet GetBillManage()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetBillManage", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 删除票据管理信息
    /// </summary>
    /// <param name="Is_Visible">删除状态1为临时删除，－1为彻底删除</param>
    /// <returns>返回删除是否成功</returns>
    public Boolean DeleteBillManage(string p_id, int Is_Visible)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteBillManage", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@p_id", SqlDbType.NVarChar, 20);
        com.Parameters["@p_id"].Value = p_id;
        com.Parameters.Add("@is_visible", SqlDbType.Int, 1);
        com.Parameters["@is_visible"].Value = Is_Visible;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 确认票据管理信息
    /// </summary>
    /// <returns>返回确认是否成功</returns>
    public Boolean AuditStatBillManage(string p_id, int AuditStat, string Auditor)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AuditStatSetBillManage", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@p_id", SqlDbType.NVarChar, 20);
        com.Parameters["@p_id"].Value = p_id;
        com.Parameters.Add("@is_audit", SqlDbType.Int);
        com.Parameters["@is_audit"].Value = AuditStat;
        com.Parameters.Add("@auditor", SqlDbType.NVarChar, 60);
        com.Parameters["@auditor"].Value = Auditor;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 增加票据管理信息
    /// </summary>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    /// 
    public Boolean AddBillManage(string p_id, DateTime p_date, DateTime sddate, DateTime qfdate, DateTime dqdate, string pp_no, string cdUnit, string cdBank, string bsUnit, decimal bsmoney, bool p_type, decimal p_lv, decimal p_value, string dp_id, string wk_id, string Remark, string Oper)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddBillManage", con);

        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@p_id", SqlDbType.NVarChar, 30);
        com.Parameters["@p_id"].Value = p_id;
        com.Parameters.Add("@p_date", SqlDbType.DateTime);
        com.Parameters["@p_date"].Value = p_date;
        com.Parameters.Add("@sddate", SqlDbType.DateTime);
        com.Parameters["@sddate"].Value = sddate;
        com.Parameters.Add("@qfdate", SqlDbType.DateTime);
        com.Parameters["@qfdate"].Value = qfdate;
        com.Parameters.Add("@dqdate", SqlDbType.DateTime);
        com.Parameters["@dqdate"].Value = dqdate;
        com.Parameters.Add("@pp_no", SqlDbType.NVarChar);
        com.Parameters["@pp_no"].Value = pp_no;
        com.Parameters.Add("@cdUnit", SqlDbType.NVarChar, 255);
        com.Parameters["@cdUnit"].Value = cdUnit;
        com.Parameters.Add("@cdBank", SqlDbType.NVarChar, 255);
        com.Parameters["@cdBank"].Value = cdBank;
        com.Parameters.Add("@bsUnit", SqlDbType.NVarChar, 255);
        com.Parameters["@bsUnit"].Value = bsUnit;
        com.Parameters.Add("@bsmoney", SqlDbType.Decimal);
        com.Parameters["@bsmoney"].Value = bsmoney;
        com.Parameters.Add("@p_type", SqlDbType.Bit);
        com.Parameters["@p_type"].Value = p_type;
        com.Parameters.Add("@p_value", SqlDbType.Decimal);
        com.Parameters["@p_value"].Value = p_value;
        com.Parameters.Add("@p_lv", SqlDbType.Decimal);
        com.Parameters["@p_lv"].Value = p_lv;        
        com.Parameters.Add("@dp_id", SqlDbType.NVarChar, 30);
        com.Parameters["@dp_id"].Value = dp_id;
        com.Parameters.Add("@wk_id", SqlDbType.NVarChar, 30);
        com.Parameters["@wk_id"].Value = wk_id;
        com.Parameters.Add("@oper", SqlDbType.NVarChar, 30);
        com.Parameters["@oper"].Value = Oper;
        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 修改票据管理信息
    /// </summary>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    public Boolean UpDateBillManage(string p_id, DateTime p_date, DateTime sddate, DateTime qfdate, DateTime dqdate, string pp_no, string cdUnit, string cdBank, string bsUnit, decimal bsmoney, decimal p_lv, decimal p_value, string dp_id, string wk_id, string Remark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpDateBillManage", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@p_id", SqlDbType.NVarChar, 30);
        com.Parameters["@p_id"].Value = p_id;
        com.Parameters.Add("@p_date", SqlDbType.DateTime);
        com.Parameters["@p_date"].Value = p_date;
        com.Parameters.Add("@sddate", SqlDbType.DateTime);
        com.Parameters["@sddate"].Value = sddate;
        com.Parameters.Add("@qfdate", SqlDbType.DateTime);
        com.Parameters["@qfdate"].Value = qfdate;
        com.Parameters.Add("@dqdate", SqlDbType.DateTime);
        com.Parameters["@dqdate"].Value = dqdate;
        com.Parameters.Add("@pp_no", SqlDbType.NVarChar);
        com.Parameters["@pp_no"].Value = pp_no;
        com.Parameters.Add("@cdUnit", SqlDbType.NVarChar, 255);
        com.Parameters["@cdUnit"].Value = cdUnit;
        com.Parameters.Add("@cdBank", SqlDbType.NVarChar, 255);
        com.Parameters["@cdBank"].Value = cdBank;
        com.Parameters.Add("@bsUnit", SqlDbType.NVarChar, 255);
        com.Parameters["@bsUnit"].Value = bsUnit;
        com.Parameters.Add("@bsmoney", SqlDbType.Decimal);
        com.Parameters["@bsmoney"].Value = bsmoney;
        //com.Parameters.Add("@p_type", SqlDbType.Bit);
        //com.Parameters["@p_type"].Value = p_type;
        com.Parameters.Add("@p_value", SqlDbType.Decimal);
        com.Parameters["@p_value"].Value = p_value;
        com.Parameters.Add("@p_lv", SqlDbType.Decimal);
        com.Parameters["@p_lv"].Value = p_lv;
        com.Parameters.Add("@dp_id", SqlDbType.NVarChar, 30);
        com.Parameters["@dp_id"].Value = dp_id;
        com.Parameters.Add("@wk_id", SqlDbType.NVarChar, 30);
        com.Parameters["@wk_id"].Value = wk_id;
        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

}
